package com.xingda.packing.dmds.minitor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xingda.packing.dmds.common.dto.PageDto;
import com.xingda.packing.dmds.enums.LogType;
import com.xingda.packing.dmds.minitor.entity.PkRuntime;
import com.xingda.packing.dmds.minitor.mapper.PkRuntimeMapper;
import com.xingda.packing.dmds.minitor.service.IPkRuntimeService;
import org.springframework.stereotype.Service;

@Service("pkRuntimeDMDSService")
public class PkRuntimeService extends ServiceImpl<PkRuntimeMapper, PkRuntime> implements IPkRuntimeService {
    @Override
    public Page<PkRuntime> getRunTime(PageDto dto) {
        LambdaQueryWrapper<PkRuntime> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.ge(PkRuntime::getCreateTime, dto.getStart());
        lambdaQueryWrapper.lt(PkRuntime::getCreateTime, dto.getEnd());
        if (dto.getArea() != 0) {
            lambdaQueryWrapper.eq(PkRuntime::getLogLevel, LogType.getById(dto.getArea()));
        }
        lambdaQueryWrapper.orderByDesc(PkRuntime::getCreateTime);
        Page<PkRuntime> page = new Page<>(dto.getCurrent(), dto.getPagesize());
        this.baseMapper.selectPage(page, lambdaQueryWrapper);
        return page;
    }
}
